<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewpoint" content="width=device,initial-scale=1">
    <link href="font-awesome-4.7.0/css/font-awesome.css" rel="stylesheet">
    <link href="reset.css" rel="stylesheet">
    <link href="icon.css" rel="stylesheet">
    <link href="businessList.css" rel="stylesheet">
    <title>饿了么 商家列表</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>

<body>
    <div class="wrapper">
        <!--    header部分-->
        <header>
            <p>商家列表</p>
        </header>
        <!--    商家列表部分-->
        <ul class="business">
            <!--        点击标题外和底部菜单部分跳转info-->
            <!-- <li onclick="location.href='businessInfo.html'">
                <div class="business-img">
                    <img src="img/sj01.png">
                    <div class="business-img-quantity">3</div>
                </div>
                <div class="business-info">
                    <h3>万家饺子（软件园E18店）</h3>
                    <p>&#165;15起送 | &#165;3配送</p>
                    <p>各种饺子炒菜</p>
                </div>
            </li> -->
        </ul>
        <!--    底部菜单部分-->
        <ul class="footer">
            <!--        跳转首页-->
            <li onclick="location.href='index.html' ">
                <i class="fa fa-home"></i>
                <p>首页</p>
            </li>
            <li onclick="location.href='Message.html'">
                <i class="fa fa-compass"></i>
                <p>消息</p>
            </li>
            <!--        跳转订单-->
            <li onclick="location.href='orderList.html' ">
                <i class="fa fa-file-text-o"></i>
                <p>订单</p>
            </li>
            <li onclick="location.href='Person.html' ">
                <i class="fa fa-user-o"></i>
                <p>我的</p>
            </li>
        </ul>
    </div>
</body>
<script>
    function getURLParameter(name) {
        // 获取 URL 中的查询字符串部分
        var urlParams = new URLSearchParams(window.location.search);
        // 返回指定参数的值
        return urlParams.get(name);
    }
    function goDetail(shopId) {
        window.location.href = 'businessInfo.html?id=' + shopId;
    }
    $(document).ready(function () {
        var shopType = getURLParameter('shopType');
        console.log(shopType);
        $.ajax({
            url: 'http://127.0.0.1:8081/shop/listShopByShopType?shopType=' + shopType, // 替换为实际的注册 API URL
            type: 'GET',
            contentType: 'application/json; charset=UTF-8', // 设置内容类型为 JSON
            data: {},
            success: function (res) {
                if (res.flag) {
                    console.log(res)
                    var html = [];
                    for (var i = 0; i < res.data.length; i++) {
                        html.push('<li onclick="goDetail('+res.data[i].shopId+')">')
                        html.push('	<div class="business-img">                     ')
                        html.push('		<img src="'+res.data[i].shopImg+'">                   ')
                        // html.push('		<div class="business-img-quantity">3</div> ')
                        html.push('	</div>                                         ')
                        html.push('	<div class="business-info">                    ')
                        html.push('		<h3>'+res.data[i].shopName+'</h3>           ')
                        html.push('		<p>&#165;'+res.data[i].startPrice+'起送 | &#165;'+res.data[i].deliveryPrice+'配送</p>          ')
                        html.push('		<p>'+res.data[i].shopExplain+'</p>                        ')
                        html.push('	</div>                                         ')
                        html.push('</li>                                           ')

                    }
                    $('.business').html(html.join(''));
                } else {
                    alert(res.message)
                }
            },
            error: function (xhr, status, error) {
                alert('查询失败：' + xhr.statusText);
            }
        });
    });
</script>
</html>